<?php
/**
 * Created by PhpStorm.
 * User: haobin
 * Date: 2016/11/15
 * Time: 9:14
 * description:最近五天的用户数据
 */
require('../conn.php');
require('../functions.php');
require('admin.php');
$uid = $_GET['uid'];
$today = date("Y-m-d",time());
$lastFiveDay = date("Y-m-d",time()-24*60*60*5);
$sql = "select day,uid from sharedata WHERE uid={$uid} AND day >= '{$lastFiveDay}' GROUP BY day ORDER BY day DESC";
$row = $mysql->query($sql);
?>
<?php include('head.php') ?>
<div class="container-fluid">
    <div class="row-fluid">
        <?php
        include('left.php'); ?>
        <div class="span9">
            <h1 class="page-title">近五天统计</h1>
            <div class="well">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <div class="well">
                            <div class="pull-right">
                                <a href="?page=<?=$page_1?>">上一页</a>
                                <a href="?page=<?=$page_2?>">下一页</a>
                            </div>
                            <table class="table">
                                <thead>
                                <tr>
                                    <th>日期</th>
                                    <th>用户id</th>
                                    <th>文章总量</th>
                                    <th>广告总量</th>
                                    <th>广告率</th>
                                    <th>安卓|(百分点)</th>
                                    <th>苹果|(百分点)</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                foreach ($row as $tx) {
                                    $article = $mysql->query("select count(id) as num from sharedata where `uid`={$tx['uid']} AND `day`='{$tx['day']}' AND TYPE != 2");
                                    $ad = $mysql->query("select count(id) as num from adpv WHERE `uid`={$tx['uid']} AND `day`='{$day}'");
                                    $android = $mysql->query("SELECT count(id) as num from sharedata where  `day`='{$tx['day']}' AND uid={$tx['uid']} AND type != 2 AND device='android'");
                                    $anpercent = number_format($android[0]['num']/$article[0]['num'],2);
                                    $apple = $mysql->query("SELECT count(id) as num from sharedata where  `day`='{$tx['day']}' AND uid={$tx['uid']} AND type != 2 AND device='iphone'");
                                    $appercent = number_format($apple[0]['num']/$article[0]['num'],2);
                                    $adpercent = number_format($ad[0]['num']/$article[0]['num'],2);
                                    print <<<table
        <tr>
          <td>{$tx['day']}</td>
		  <td>{$tx['uid']}</td>
		  <td>{$article[0]['num']}</td>
		  <td>{$ad[0]['num']}</td>
		  <td>{$adpercent}</td>
		  <td>{$android[0]['num']}|({$anpercent})</td>
		  <td>{$apple[0]['num']}|($appercent)</td>
        </tr>
table;
                                } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="profile">
                    </div>
                </div>

            </div>

        </div>
    </div>
</div>
<script src="lib/bootstrap/js/bootstrap.js"></script>
</body>
</html>

